package com.clyz.material.controller;

import com.clyz.material.entity.es.Material;
import com.clyz.material.service.es.IMaterialElasticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1></h1>
 *
 * @author Zemin.Yang
 */
@Log4j2
@RestController
@RequestMapping("es/material")
@AllArgsConstructor
@Api(tags = {"资料 ES "})
public class MaterialElasticController {
    private final IMaterialElasticService elasticService;

    @PutMapping("addOrUpdateBatch")
    @ApiOperation(value = "批量更新及新增")
    public List<Material> addOrUpdateBatch(@RequestBody List<Material> materials) {
        return elasticService.addOrUpdateBatch(materials);
    }

    @GetMapping("findById/{id}")
    public Material findById(@PathVariable String id) {
        return elasticService.findById(id);
    }

    @DeleteMapping("delete/{id}")
    public void delete(@PathVariable String id) {
        elasticService.delete(id);
    }

    @GetMapping("search")
    public Page<Material> search(String content,
                                 @RequestParam(defaultValue = "0") int page,
                                 @RequestParam(defaultValue = "10") int size) {
        return elasticService.search(content, 1, page, size);
    }
}
